package com.hgkj.common.core.utils;


import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * 网络请求工具类
 */
public class RequestUtils {

    /**
     * 获取请求参数
     */
    public static String getParameter(String paramName) {
        return getRequest().getParameter(paramName);
    }
    /**
     * 获取请求参数，包含默认值
     */
    public static String getParameter(String paramName, String defaultValue) {
        return Convert.toStr(getParameter(paramName), defaultValue);
    }

    private static HttpServletRequest getRequest(){
        return getServletRequestAttributes().getRequest();
    }

    private static ServletRequestAttributes getServletRequestAttributes(){
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        return (ServletRequestAttributes) requestAttributes;
    }
}
